﻿<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>健身中心</title>
    <link href="../css/mui.min.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../css/orderApply.css" />
     <link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css">
   <script src="../script/mui.min.js"></script>
  <script src="../script/mui.picker.min.js"></script>
    <script type="text/javascript" src="../script/jquery-1.12.4.min.js"></script>
    <script src="../script/JsUrl.js" type="text/javascript"></script>
    <script src="../script/utils.js"></script>
    <script src="../script/oderApply.js"></script>
 <!--        <script src="../bootstrap/js/jquery/2.0.0/jquery.min.js"></script>
<link href="../bootstrap/css/bootstrap/3.3.6/bootstrap.min.css" rel="stylesheet">
<script src="../bootstrap/js/bootstrap/3.3.6/bootstrap.min.js"></script> -->
    <!-- <script type="text/javascript" src="../script/orderApply.js"></script> -->
</head>
<body onclick="check();" style="background: #fff">
<!-- <div style="position: relative;"> -->

		<div class="mui-content" style="background: #fff;height: 80%">
			<div class="mui-card" style="margin-left: 3%;">
				<div class="mui-input-row">
          <img src="../img/y_qicai.png"  class="logo" >
				<label>设备名称:</label>
				<input type="text" id="qicaimingcheng"  readonly="readonly" style="padding-left: 20px;   float:left;" class="mui-input-clear" disabled>
				</div>
				<div class="mui-input-row">
           <img src="../img/y_yuyueren.png"  class="logo">
					<label>预约人:</label>
					<input type="text" id="yuyueren"  readonly="readonly" style="padding-left: 20px;   float:left;" class="mui-input-clear" disabled>
				</div>
        <div class="mui-input-row">
           <img src="../img/shebei.png"  class="logo">
          <label>设备编号:</label>
          <input type="text" id="shebeibianhao"  readonly="readonly" style="padding-left: 20px;   float:left;" class="mui-input-clear" disabled>
        </div>
				<div class="mui-input-row">
           <img src="../img/y_shoujihao.png" class="logo" >
					<label>手机号:</label>
					<input type="tel" id="phone"  onBlur="check()" style="padding-left: 20px;   float:left;" maxlength='11' class="mui-input" placeholder="请输入手机号">
				</div>

        <div class="mui-input-row">
           <img src="../img/demail.png" class="logo" >
          <label>邮箱:</label>
          <input type="text" id="demail"  onBlur="check()"  style="padding-left: 20px;   float:left;" maxlength='30' class="mui-input" placeholder="请输入邮箱">
        </div>
       

				<div class="mui-input-row">
           <img src="../img/y_riqi.png" class="logo" >
					<label>选择日期:</label>
					<input type="text" id="selectData"  readonly="readonly" style="padding-left: 20px;   float:left;" onclick="dianji_riqi()"  disabled="disabled" disabled="disabled" class="mui-input-clear" placeholder="请填写选择日期">
				</div>
				<div class="mui-input-row">
           <img src="../img/y_shijian.png" class="logo" >
					<label style="width:30%;">预约时间:</label>
					<input type="text" class="mui-input" id="qishishijian"  readonly="readonly" onclick="dianji_qishishijian()"  placeholder="开始时间"   disabled="disabled" style="text-align: center;width:25%; float:left;margin-right: -6px;"><span style="float:left;margin-top: 8px;">~</span>
					<input type="text" class="mui-input" id="jiezhishijian"  readonly="readonly" onclick="dianji_jiezhishijian()"  disabled="disabled" placeholder="结束时间" style="text-align: center;width:29%; padding-left:17px; float:left;">
				</div>
				<div class="mui-input-row">
           <img src="../img/y_yaoqing.png"  class="logo">
					<label>邀约伙伴:</label>
				<button style="width:23%;  margin-right: 10px;padding: 5px 0px 4px 0px" type="button" onclick="tianjiarenyuan()" class="mui-btn  mui-btn-primary">＋添加人员</button>
				</div>
				<div class="remark" id="InvitUsersdd" style="display: none">
           <img src="../img/y_huoban.png"  class="logo">
          <p style="height:20px;color: #000">您邀约的人员:</p>
          <textarea rows="3" cols="120" type="text" id="InvitUsers" placeholder=""   maxlength="150"  readonly="readonly" style="height:50%;width:90%;word-wrap:break-word; word-break:break-all;margin-left:5%;"></textarea>
           <div class="line"></div>
        </div>

				<div class="remark" id="div3">
           <img src="../img/y_beizhu.png" class="logo" >
					<p style="margin-left: 3px;height:20px;color: #000">备注:<span style="margin-left: 20PX;color: #A3A3A3">限制在30字以内</span></p>
					<textarea   rows="3" cols="120" type="text" id="beizhu"  name="beizhu"   maxlength="30" style="height:50%;width:90%;word-wrap:break-word; word-break:break-all;margin-left:5%;"></textarea>
				</div>
         
			</div>
		</div>

 <div  id="div2" class="button" style="padding-top: 20%" >
             <button id="order_BigButton" class="button_style" onclick="submit_shujv()"   disabled="disabled"><span class="button_name">提交申请</span>
             </button>
  </div>


<!-- </div> -->
</body>


<script type="text/javascript">

    var order_phone;
    var order_Data;
    var order_yuyueqishishijian;
    var order_yuyuejiezhishijian;
    var order_beizhu;
    var startTime;
    var endTime;
    var tioazhuan=0;
    var sons="";  //受邀人json
    var last;//受约人
    var inviteJson="[";//新 受邀人json 2018/2/7
    var shouyaoemail="\"selected\":[]";
     $(function() { 
      //mui初始化
      mui.init({
        swipeBack:true //启用右滑关闭功能
      });
        
  
          //获取界面传值
      getValue();
        check();
        
    
	}); 
     //添加人员按钮的点击事件
  function tianjiarenyuan(){
         
         //alert(shouyaoemail);
         document.getElementById("InvitUsersdd").style.display="";
         //window.native.webOpenselection("","ContactCallBlack");
	   window.native.webSelectContact("{"+shouyaoemail+",\"mode\":\"\",\"organize\":\"\"}","ContactCallBlack")


      }

   var DeviceID;//设备ID
    var DeviceName;//设备名称
    var OrderUserName;//预约人姓名
    var UserEmail;//预约人工号
    var OrderUserId;//预约人用户ID
    var UserTel;//预约人用户手机号
    var UserTeamId;//部门 id 
     var CatagpruName;//设备列别
    
    var flage=-1;
    
    function getValue() {
	deviceNumber = utils.getParam("deviceNumber");
        DeviceID = utils.getParam("DeviceId");
        DeviceName = utils.getParam("deviceName");
        OrderUserName = utils.getParam("orderUserName");
        UserEmail = utils.getParam("UserEmail");
        OrderUserId = utils.getParam("orderUserID");
        UserTel = utils.getParam("UserTel");
        UserTeamId = utils.getParam("UserTeamId");
		CatagpruName = utils.getParam("CatagpruName");
        
        document.getElementById('qicaimingcheng').value = DeviceName;
        document.getElementById('yuyueren').value = OrderUserName;
        document.getElementById('phone').value = UserTel;
        document.getElementById('demail').value = UserEmail;
        document.getElementById('shebeibianhao').value = deviceNumber;

        
    }
    
    
/*var personArray;//邀约的伙伴数组*/
//webOpenselection返回调用函数
function ContactCallBlack(ContactCall){

  var son_json="";

  sons = $.parseJSON( ContactCall ); 
  //alert(ContactCall);
shouyaoemail="\"selected\":[";
 /*personArray = new  new Array(sons.length);*/
  if(sons.length<=0){
    document.getElementById("InvitUsersdd").style.display="none";
    document.getElementById("InvitUsers").value="";
    sons="";
shouyaoemail="\"selected\":[]";
  }
   document.getElementById("InvitUsers").value="  ";
   for (var i = 0; i < sons.length; i++) {
        var userName = sons[i].username;
        document.getElementById("InvitUsers").value+=userName+"  ";
        var email = sons[i].email;
        var mobile= sons[i].mobile;
        var userid= sons[i].userid;
        var userteamidd= sons[i].organizeid;

        
        if(i==sons.length-1){
             son_json ="{'email':'"+email+"','mobile':'"+mobile+"','userid': '"+userid+"','username': '"+userName+"','userteamid': '"+userteamidd+"'}";  
       		 var uemail = sons[i].email;
 		shouyaoemail+="\""+uemail+"\"]";
	 }else{
             son_json ="{'email':'"+email+"','mobile':'"+mobile+"','userid': '"+userid+"','username': '"+userName+"','userteamid': '"+userteamidd+"'},";
      	      var uemail = sons[i].email;
 	       shouyaoemail+="\""+uemail+"\",";
	  }
        inviteJson+=son_json;
    }
    //[{'email':'byw_cgb@faw.com.cn','mobile':'13804310597','userid': '8a05c12f4b4959c0014b495a3e4d02ff','username': '白宇威'}]
    inviteJson+="]";

    
    sons= ContactCall;
    //alert(inviteJson);
  //alert(typeof sons);
}


    function back_onclick() {
          window.close();
    }
	

    //提交表单
    function submit_shujv() {

     

        order_phone = document.getElementById("phone").value;
        // alert(order_phone);
        order_Data = document.getElementById("selectData").value;
        //alert(order_Data);
        order_yuyueqishishijian = document.getElementById("qishishijian").value;
        //alert(order_yuyueqishishijian);
        order_yuyuejiezhishijian = document.getElementById("jiezhishijian").value;
       
        order_beizhu = document.getElementById("beizhu").value;
       // alert(order_beizhu);
        startTime = order_Data +" " + order_yuyueqishishijian +":59";

        endTime = order_Data +" " + order_yuyuejiezhishijian +":00";

        
        //做时间验证 成功之后传给后台
         getRequestByDeviceIdAndStartTimeAndEndTime(DeviceID,startTime,endTime);
            
         
    }

//根据设备id，起始时间结束时间验证是否冲突，冲突则返回冲突信息，否则跳转到SubmitFromDataToService();
function getRequestByDeviceIdAndStartTimeAndEndTime(DeviceID,startTime,endTime){
 //alert(DeviceID+"   "+startTime+"    "+endTime);
//http://fawyy.sunnyit.cn:8222/Subscribe/getSubscribeByIdAndTime?subscribe_device_id=11&subscribe_begintime=2017-12-11%2012:06:00&subscribe_endtime=2017-12-11%2012:50:59
 var SubmitFromDataToServicey_URL =URL_1+"getSubscribeByIdAndTime"; //查询设备类别

  $.ajax({
      url: SubmitFromDataToServicey_URL,
      type: 'GET',
      dataType: 'json',
      cache: false,
      data: {
          subscribe_device_id: DeviceID, //用户ID
          subscribe_begintime: startTime, //开始时间
          subscribe_endtime: endTime //结束时间
      },
      beforeSend: LoadFunction, //加载执行方法
      error: erryFunction, //错误执行方法
      success: succFunction //成功执行方法
  })

  function LoadFunction() {
      //$(".header1").html('加载中...');
  }

  function erryFunction() {
      window.native.toast("时间验证超时！");
  }

  function succFunction(JsonString) {
      json = eval(JsonString);
	 //alert(JSON.stringify(json));
      if (json.code > 0) {
           //alert(json.msg);
           SubmitFromDataToService();
      } else {
          window.native.toast("时间验证冲突");
         var msg_name=json.extend.getSubscribeByIdAndTime[0].subscribeUserName;
         var msg_qishishijian=json.extend.getSubscribeByIdAndTime[0].subscribeBeginTime;
         var msg_jeizhishijian=json.extend.getSubscribeByIdAndTime[0].subscribeEndTime;
         var msg_shijian=fmtDate(msg_qishishijian,msg_jeizhishijian);
         
          mui.alert("当前选择的时间段已被【"+msg_name+"】预约\n冲突时间段："+msg_shijian,"提示");
          
      }
    
  }
}
	//上传数据
    function SubmitFromDataToService() { 
    
            //alert(UserTeamId+"    "+inviteJson);
        var SubmitFromDataToServicey_URL =URL_1+"insertSubscribeForApp";
        //document.getElementById("beizhu").value=OrderUserId+"---"+UserEmail+"---"+DeviceID+"---"+startTime+"---"+endTime+"---"+OrderUserName+"---"+order_phone+"---"+order_beizhu+"---"+UserTeamId+"---"+inviteJson;
        $.ajax({
            url: SubmitFromDataToServicey_URL,
            type: 'GET',
            dataType: 'json',
            cache: false,
            data: {
                subscribe_user_id: OrderUserId, //用户ID
                subscribe_user_email: UserEmail, //邮箱
                subscribe_device_id: DeviceID, //设备ID
                subscribe_begin_time: startTime, //开始时间
                subscribe_end_time: endTime, //结束时间
                subscribe_user_name: OrderUserName, //预约人
                subscribe_user_mobile: order_phone, //手机号
                subscribe_remark: order_beizhu, //备注
                //subscribe_sons:sons//受邀人
                subscribe_organize_id:UserTeamId,
                subscribe_sons:inviteJson//新受邀人 2018/2/7

            },
            beforeSend: LoadFunction, //加载执行方法
            error: erryFunction, //错误执行方法
            success: succFunction //成功执行方法
        })

        function LoadFunction() {
            //$(".header1").html('加载中...');
        }

        function erryFunction() {
        	window.location.replace("orderSu.html?CatagpruName="+CatagpruName+"&DeviceID="+DeviceID+"");
           // window.native.toast("上传-数据--超时!!!");
          // window.native.toast("预约成功");
		//if(history.length>1){
		//history.go(-2);
		//}else{
		//window.location.href = "./MyOrder.html";
		//}
        }

        function succFunction(JsonString) {
            json = eval(JsonString);
            if (json.code > 0) {
		window.location.replace("orderSu.html?CatagpruName="+CatagpruName+"&DeviceID="+DeviceID+"");
               // window.native.toast("预约成功");
		//if(history.length>1){
		//history.go(-2);
		//}else{
		//window.location.href = "./MyOrder.html";
		//}
            } else {
                window.native.toast("请输入合理的时间");
            }
           
        }

    };
    /*
		拼接时间字符串 " m月d日 week h:m ~ h:m "
    */
    function fmtDate(stime,etime) {
    var startTime = new Date(stime);
    var endTime = new Date(etime);
    var weekStr = "星期" + "日一二三四五六".charAt(startTime.getDay());
//  var y = date.getFullYear();
    var m = startTime.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = startTime.getDate();
    d = d < 10 ? ('0' + d) : d;
    var startHour = startTime.getHours();
    startHour = startHour < 10 ? ('0' + startHour) : startHour;
    var startminute = startTime.getMinutes();
    startminute = startminute < 10 ? ('0' + startminute) : startminute;
    
    var endHour = endTime.getHours();
    endHour = endHour < 10 ? ('0' + endHour) : endHour;
    var endminute = endTime.getMinutes();
    endminute = endminute < 10 ? ('0' + endminute) : endminute;
    
    var result = m + '月' + d + '日 ' +weekStr +" "+ startHour + ':' + startminute + '~'
    + endHour +":"+ endminute;
    return result;
};
    
</script>

</html>
